package com.example.wanandroid.service.impl;

import com.example.wanandroid.mapper.UserMapper;
import com.example.wanandroid.pojo.User;
import com.example.wanandroid.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Desc TODO
 * @Date 2020/4/13 13:41
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public PageInfo<HashMap<String, Object>> getUsers(int page, int pageSize) {
        //设置分页信息
        PageHelper.startPage(page, pageSize);
        List<HashMap<String, Object>> mapList = userMapper.getUsers();
        //获取分页信息
        PageInfo<HashMap<String, Object>> pageInfo = new PageInfo<>(mapList);
        return pageInfo;
    }

    @Override
    public User selectUserByUsername(String username) {
        return userMapper.selectUserByUsername(username);
    }

    @Override
    public int insert(User user) {
        return userMapper.insertSelective(user);
    }

    @Override
    public User selectByPrimaryKey(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }
}
